﻿module Sustainalytics.EsgRatings {

    export class EsgThemeOverallPerformanceSummaryService implements IEsgThemeOverallPerformanceSummaryService {

        constructor(
            private $q: ng.IQService,
            private $http: ng.IHttpService) {
        }

        public get(companyId: string, theme?: EsgThemeEnum): ng.IPromise<EsgThemeOverallPerformanceSummaryDto> {

            var ctx = this;

            var def = ctx.$q.defer();

            var params =
                {
                    theme: theme
                };

            var url = '/esgratingserv/api/v1/company/' + companyId + '/esgThemeOverallPerformanceSummary?' + $.param(params);

            var promise = ctx.$http.get(url).then(
                // success
                function (res: ng.IHttpPromiseCallbackArg<EsgThemeOverallPerformanceSummaryDto>) {
                    def.resolve(res.data);
                },
                // error
                function (res: ng.IHttpPromiseCallbackArg<EsgThemeOverallPerformanceSummaryDto>) {
                    def.reject(res);
                });

            return def.promise;
        }
    }


    export var esgThemeOverallPerformanceSummaryServiceName = 'EsgThemeOverallPerformanceSummaryService';

    angular.module(esgRatingsModuleName).service(esgThemeOverallPerformanceSummaryServiceName, EsgThemeOverallPerformanceSummaryService);
}